package com.ctgu.tengyun.bean.convert;

import com.ctgu.tengyun.bean.request.SparePartDetail;
import com.ctgu.tengyun.bean.response.SparePartListResponse;
import com.ctgu.tengyun.domain.SparePartInfo;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/6.
 */
public class SparePartConvert {

    public static SparePartListResponse toSparePartListResponse(Integer totalCount,
                                                                Integer pageSize,
                                                                List<SparePartInfo> sparePartInfoList) {
        SparePartListResponse response = new SparePartListResponse();

        response.setTotalCount(totalCount);
        response.setTotalPage((int) Math.ceil(totalCount / (double) pageSize));

        List<SparePartDetail> sparePartDetailList = new ArrayList<>(sparePartInfoList.size());
        sparePartInfoList.forEach(item -> {
            SparePartDetail detail = new SparePartDetail();
            BeanUtils.copyProperties(item, detail);
            detail.setGraphFile(FileConvert.fillFileBeanUrlPath(detail.getGraphFile()));

            sparePartDetailList.add(detail);
        });

        response.setSparePartList(sparePartDetailList);
        return response;

    }

}
